/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package recanto.das.pedrinhas;

import java.util.ArrayList;
import java.util.List;
import recanto.das.pedrinhas.bean.Cliente;
import recanto.das.pedrinhas.controller.ClienteController;
import recanto.das.pedrinhas.dao.ClienteDao;

/**
 *
 * @author Acesso Diego
 */
public class FrameReservaEtapa2 extends javax.swing.JFrame {

    /**
     * Creates new form NewJFrame
     */
    public FrameReservaEtapa2() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jComboBox1 = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton4 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jComboBox1.setEditable(true);
        jComboBox1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        jButton1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagem/add.png"))); // NOI18N
        jButton1.setText("Adicionar");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                int index =  sbm.getSelectedIndex();
                dependente.add(ControleReserva.clientes.get(index));
                for (int i = 0; i < dependente.size(); i++){
                    matrizDependentes[i][0] = dependente.get(i).getNome();
                    matrizDependentes[i][1] = dependente.get(i).getRg();
                    matrizDependentes[i][2] = dependente.get(i).getDatanasc().toString();
                    matrizDependentes[i][3] = dependente.get(i).getEmail();
                }
                jTable1.setModel(new javax.swing.table.DefaultTableModel(
                    matrizDependentes,
                    new String [] {
                        "Nome", "RG", "Data Nasc.", "Email"
                    }));

                    System.out.println(matrizDependentes[0][0]);
                }
            });

            jLabel2.setFont(new java.awt.Font("Ubuntu", 1, 18)); // NOI18N
            jLabel2.setText("Entre com os Acompanhantes:");

            jLabel3.setFont(new java.awt.Font("Ubuntu", 1, 18)); // NOI18N
            jLabel3.setText("Acompanhante não cadastrado?");

            jButton2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
            jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagem/cadastrarOk.png"))); // NOI18N
            jButton2.setText("Cadastrar Acompanhante");
            jButton2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton2ActionPerformed(evt);
                }
            });

            jLabel4.setFont(new java.awt.Font("Ubuntu", 1, 18)); // NOI18N
            jLabel4.setText("Lista de Acompanhantes");

            jTable1.setFont(new java.awt.Font("Ubuntu", 0, 18)); // NOI18N
            jTable1.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null}
                },
                new String [] {
                    "Nome", "RG", "Data Nasc.", "Email"
                }
            ) {
                Class[] types = new Class [] {
                    java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
                };

                public Class getColumnClass(int columnIndex) {
                    return types [columnIndex];
                }
            });
            jTable1.setRowHeight(20);
            jTable1.setRowMargin(5);
            jScrollPane1.setViewportView(jTable1);

            jButton4.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
            jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagem/left.png"))); // NOI18N
            jButton4.setText("Voltar");
            jButton4.setActionCommand("ReservaEtapa1");
            jButton4.addActionListener(new ControleReserva());

            jButton3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
            jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagem/right.png"))); // NOI18N
            jButton3.setText("Próximo");
            jButton3.setMaximumSize(new java.awt.Dimension(160, 25));
            jButton3.setMinimumSize(new java.awt.Dimension(160, 25));
            jButton3.setActionCommand("ReservaEtapa3");
            jButton3.addActionListener(new ControleReserva());

            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addGap(0, 182, Short.MAX_VALUE)
                            .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(8, 8, 8)
                            .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel4)
                                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel3)
                                        .addComponent(jLabel2))
                                    .addGap(0, 0, Short.MAX_VALUE)))))
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(40, 40, 40)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton1))
                    .addGap(44, 44, 44)
                    .addComponent(jLabel3)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addComponent(jLabel4)
                    .addGap(18, 18, 18)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton4)
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(21, 21, 21))
            );

            java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
            setBounds((screenSize.width-616)/2, (screenSize.height-540)/2, 616, 540);
        }// </editor-fold>//GEN-END:initComponents
    
    public void setTitulares(){
        System.out.println("aki");
        ControleReserva cr = new ControleReserva();
        System.out.println(cr.getTitular().getNome());
        //--------começa aki---------
        Cliente titular = cr.getTitular();
        ClienteController cc = new ClienteController();
        String dependentes ="";
        if (dependente.size() > 0){
            for (int i = 0; i < dependente.size(); i++) { 
                if (i==0){
                    dependentes = (dependente.get(i).getIdCli()+",");
                    System.out.println("aki1");
                }else{
                    dependentes = (dependentes+dependente.get(i).getIdCli()+",");
                    System.out.println("aki2");
                }
            }
        }
        
        cc.alterarCliente(titular, dependentes);
        cc.fechaSession();
    }
    
    public void modifica (){
        ClienteDao cd = new ClienteDao();
        ControleReserva.clientes =(ArrayList<Cliente>) cd.carregaClientes();
       // String nomes [] = new String[ControleReserva.clientes.size()]; 
       // for (int i=0; i < ControleReserva.clientes.size(); ++i ) {
       //     nomes[i] = ControleReserva.clientes.get(i).getNome();
       // }
        cd.fechaSession();
        sbm = new SearchBoxModel(jComboBox1, ControleReserva.clientes);
        jComboBox1.setModel(sbm);
        jComboBox1.addItemListener(sbm);
    }
    
    public void limpaTabela(){
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
        new Object [][] {
            {null, null, null, null},
            {null, null, null, null},
            {null, null, null, null},
            {null, null, null, null}
        },
        new String [] {
            "Nome", "RG", "Data Nasc.", "Email"
        }));
        dependente = new ArrayList<Cliente>();
        matrizDependentes = new String[48][4];
        ClienteController cc = new ClienteController();
        cc.fechaSession();
        
    }
    
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        FrameFichaCadastroAcompanhante fichaAcompanhante = new FrameFichaCadastroAcompanhante();
        fichaAcompanhante.setVisible(true);
    }//GEN-LAST:event_jButton2ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrameReservaEtapa2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrameReservaEtapa2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrameReservaEtapa2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrameReservaEtapa2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new FrameReservaEtapa2().setVisible(true);
            }
        });
    }
    
    private SearchBoxModel sbm ;
    ArrayList<Cliente> dependente = new ArrayList();
    String matrizDependentes[][] = new String[48][4];
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
}
